package cn.datawin.bms.modules.customer.controller;

import cn.datawin.bms.customer.entity.CstmCmppServerInfoEntity;
import cn.datawin.bms.modules.customer.service.CstmCmppServerInfoService;
import cn.datawin.common.core.util.R;
import cn.datawin.common.log.annotation.SysLog;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 下游cmpp-server服务器
 *
 * @author datawin-sms
 * @date 2025-06-18 09:39:02
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/customer/cmppServerInfo" )
@Tag(description = "cstmCmppServerInfo" , name = "下游cmpp-server服务器管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CstmCmppServerInfoController {

    private final CstmCmppServerInfoService cstmCmppServerInfoService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cstmCmppServerInfo 下游cmpp-server服务器
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_view')" )
    public R getCstmCmppServerInfoPage(@ParameterObject Page page, @ParameterObject CstmCmppServerInfoEntity cstmCmppServerInfo) {
        LambdaQueryWrapper<CstmCmppServerInfoEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(cstmCmppServerInfoService.page(page, wrapper));
    }
    /**
     * 获取所有下游cmpp-server服务器
     */
    @Operation(summary = "获取所有下游cmpp-server服务器" , description = "获取所有下游cmpp-server服务器" )
    @GetMapping("/listAll" )
	@PreAuthorize("isAuthenticated()")  // 只需要登录权限
    public R getAllCstmCmppServerInfo() {
        LambdaQueryWrapper<CstmCmppServerInfoEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(cstmCmppServerInfoService.list(wrapper));
    }


    /**
     * 通过id查询下游cmpp-server服务器
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(cstmCmppServerInfoService.getById(id));
    }

    /**
     * 新增下游cmpp-server服务器
     * @param cstmCmppServerInfo 下游cmpp-server服务器
     * @return R
     */
    @Operation(summary = "新增下游cmpp-server服务器" , description = "新增下游cmpp-server服务器" )
    @SysLog("新增下游cmpp-server服务器" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_add')" )
    public R save(@RequestBody CstmCmppServerInfoEntity cstmCmppServerInfo) {
        return cstmCmppServerInfoService.saveServerInfo(cstmCmppServerInfo);
    }

    /**
     * 修改下游cmpp-server服务器
     * @param cstmCmppServerInfo 下游cmpp-server服务器
     * @return R
     */
    @Operation(summary = "修改下游cmpp-server服务器" , description = "修改下游cmpp-server服务器" )
    @SysLog("修改下游cmpp-server服务器" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_edit')" )
    public R updateById(@RequestBody CstmCmppServerInfoEntity cstmCmppServerInfo) {
        return R.ok(cstmCmppServerInfoService.updateById(cstmCmppServerInfo));
    }

    /**
     * 通过id删除下游cmpp-server服务器
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除下游cmpp-server服务器" , description = "通过id删除下游cmpp-server服务器" )
    @SysLog("通过id删除下游cmpp-server服务器" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(cstmCmppServerInfoService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param cstmCmppServerInfo 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('customer_cmppServerInfo_export')" )
    public List<CstmCmppServerInfoEntity> export(CstmCmppServerInfoEntity cstmCmppServerInfo,Long[] ids) {
        return cstmCmppServerInfoService.list(Wrappers.lambdaQuery(cstmCmppServerInfo).in(ArrayUtil.isNotEmpty(ids), CstmCmppServerInfoEntity::getId, ids));
    }
}
